package com.example.sell.service.impl;

import com.example.sell.dataobject.ProductCategory;
import com.example.sell.repository.ProductCategoryRepository;
import com.example.sell.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityNotFoundException;
import java.util.List;

/**
 * @author: vince_zww
 * @date: 2020/7/24 10:44
 * @desceription:
 */
@Service
public class CategorServiceImpl implements CategoryService {

    @Autowired
    private ProductCategoryRepository repository;

    @Override
    public ProductCategory findOne(Long categoryId) {
        return repository.findById(categoryId).orElseThrow(()->new EntityNotFoundException());
    }

    @Override
    public List<ProductCategory> findAll() {
        return repository.findAll();
    }

    @Override
    public List<ProductCategory> findByCategoryTypeIn(List<Integer> categorTypeList) {
        return repository.findByCategoryTypeIn(categorTypeList);
    }

    @Override
    public ProductCategory saceOrUpdate(ProductCategory productCategory) {
        return repository.save(productCategory);
    }
}
